package com.example.camerapush.model;

import org.litepal.crud.DataSupport;

/**
 * Author:lsh
 * Version: 1.0
 * Description:
 * Date: 2018/2/28
 */

public class UpcountUtil {


    /**
     * 成功的数量+1
     * 将数量保存到数据库
     */
    public static void addSuccedCount(int albumId, int user_id) {
//        MainActivity.this.sucUpCount += 1;
        UpSuccessCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpSuccessCountBean.class);
        if (null == bean) {
            UpSuccessCountBean newBean = new UpSuccessCountBean(user_id, albumId, 1);
            newBean.save();
        } else {
            int count = bean.getCount() + 1;
            bean.setCount(count);
            bean.save();
        }
    }

    public static int getSuccessCount(int albumId, int user_id) {
        UpSuccessCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpSuccessCountBean.class);
        if (null == bean) {
            return 0;
        } else {
            return bean.getCount();
        }
    }

    /**
     * 失败的数量+1
     * 将数量保存到数据库
     */
    public static void addFailureCount(int albumId, int user_id) {
//        MainActivity.this.failureUpCount += 1;
        UpFailureCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpFailureCountBean.class);
        if (null == bean) {
            UpFailureCountBean newBean = new UpFailureCountBean(user_id, albumId, 1);
            newBean.save();
        } else {
            int count = bean.getCount() + 1;
            bean.setCount(count);
            bean.save();
        }
    }

    public static int getFailureCount(int albumId, int user_id) {
        UpFailureCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpFailureCountBean.class);
        if (null == bean) {
            return 0;
        } else {
            return bean.getCount();
        }
    }

    public static void clearSuccessCount(int albumId, int user_id) {
        UpSuccessCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpSuccessCountBean.class);
        if (null == bean) {
        } else {
            bean.setCount(0);
            bean.save();
        }
    }

    public static void clearFailureCount(int albumId, int user_id) {
        UpFailureCountBean bean = DataSupport.where("user_id = ? and album_id=?", user_id + "", albumId + "").findFirst(UpFailureCountBean.class);
        if (null == bean) {
        } else {
            bean.setCount(0);
            bean.save();
        }
    }
}
